package com.gitee.wsl.concurrent.api

fun interface RunnableWithResult<T>{
    fun run():T

    operator fun invoke(): T = run()
}

fun interface SuspendRunnableWithResult<T>{
    suspend fun run() : T

    suspend operator fun invoke() = run()
}

fun interface SuspendRunnable{
    suspend fun run()
    suspend operator fun invoke() = run()
}

fun <T> RunnableWithResult<T>.toSuspend() = SuspendRunnableWithResult { this@toSuspend.run() }

fun <T> RunnableWithResult<T>.warpResult() = RunnableWithResult{
    try {
        Result.success(run())
    } catch (e:Exception){
        Result.failure(e)
    }
}